#include <map>
#include "log/vsLogger.h"


namespace vs {
namespace log {


class LogManager
{
public:
	static bool RegisterLogOutput(std::string loggerName, LogOutput *logOutput);
	static void RemoveLogOutput(std::string loggerName, LogOutput *logOutput);

	static LogOutput* GetLogOutput(std::string loggerName);
	static Logger* GetLogger(std::string loggerName);

	LogManager& Instance() { static LogManager logManager; return logManager; }
	
private:
	LogManager(){};
	~LogManager()
	{
		ClearLoggers();
	}

	void ClearLoggers();
	
	std::map<std::string, LogOutput*> m_LogOutputs;
};

INLINE
bool LogManager::RegisterLogOutput(std::string loggerName, LogOutput *logOutput)
{
	m_LogOutputs[loggerName] = logOutput;
}

INLINE
void LogManager::RemoveLogOutput(std::string loggerName, LogOutput *logOutput)
{
	std::map<std::string, LogOutput*>::iterator it = m_LogOutputs.find(loggerName);
	m_LogOutputs.erase(it);
	//m_LogOutputs.erase(loggerName);
}

INLINE
LogOutput* LogManager::GetLogOutput(std::string loggerName)
{
	std::map<std::string, LogOutput*>::iterator it = m_LogOutputs.find(loggerName);
	if (it != m_LogOutputs.end())
	{
		return it->second;
	}
	else
	{
		return 0;
	}
}

INLINE
Logger* LogManager::GetLogger(std::string loggerName)
{
}


INLINE
void LogManager::ClearLoggers()
{
}


/*
1 create a output
FileOutput *file_output = new FileOutput("first");
FileOutput *file_output_second = new FileOutput("second", "file_out_put");

2 ask log manager to manage the log output
LogManager::Instance().RegisterLogOutput(file_output);
LogManager::Instance().RegisterLogOutput(file_output_second);

3 create a logger
Logger *logger = LogManager::GetLogger("test");

4 add the output to logger
logger->AddLogOutput();
logger->AddLogOutput();

5 log messages
logger->LogMsg(LOG_INFO, "this is a test message id = %d\r\n", 1);

*/

}
}

/*
the usage of logger
1 create a logger
Logger *logger = new Logger;
logger->Open();
logger->LogMsg();

2 creaate a logger by log manager
Logger *logger = LogManager::GetLogger("test");

3 register a logger to log manager
LogManager::RegisterLogger("test", logger);

4 set default output for all loggers managed by log manager
LogOutput *output = new LogOutput();
LogManager::SetDefaultLogOutput(output);

*/
